package DataStructure.TreeLearning.BinarySortTree;

import java.util.ArrayList;
import java.util.List;

/**
 *  测试类2 验证建树操作
 */
public class TestDemo2 {
    public static void main(String[] args) {
    MyBinarySortTreeImpl<Integer> tree =  new MyBinarySortTreeImpl<>();
    // 前序：[5, 2, 0, -4, -1, 3, 19, 12, 38]
    int[] preArr = {5, 2, 0, -4, -1, 3, 19, 12, 38};
    // 中序：[-4, -1, 0, 2, 3, 5, 12, 19, 38]
    int[] inArr = {-4, -1, 0, 2, 3, 5, 12, 19, 38};
    // 后序：[-1, -4, 0, 3, 2, 12, 38, 19, 5]
    int[] postArr = {-1, -4, 0, 3, 2, 12, 38, 19, 5};

    List<Integer> preList = new ArrayList<>();
    List<Integer> inList = new ArrayList<>();
    List<Integer> postList = new ArrayList<>();

    for(int i=0; i<preArr.length; i++) {
        preList.add(preArr[i]);
    }
    for(int i=0; i<inArr.length; i++) {
        inList.add(inArr[i]);
    }
    for(int i=0; i<postArr.length; i++) {
        postList.add(postArr[i]);
    }

    // 根据前序和中序建树
    tree.buildTreeByPreAndIn(preList, inList);
    // 根据中序和后序建树
    //tree.buildTreeByInAndPost(inList, postList);

    // 验证：
    System.out.println("PreOrder:");
    System.out.println(tree.preOrder_Stack());
    System.out.println("----------------------------");
    System.out.println("InOrder:");
    System.out.println(tree.inOrder_Stack());
    System.out.println("-----------------------------");
    System.out.println("PostOrder:");
    System.out.println(tree.postOrder_Stack());
}
}
